# -*- coding:utf-8 -*-
# @Author:🎈RedBalloon
# @Time:2022/9/27-23:53
# @File:01-爬虫体验.py
from urllib.request import urlopen

url = 'http://www.baidu.com'
# urlopen来发送请求
response = urlopen(url)
# 读取获取到的是byte类型  b'<!DOCTYPE html>  需要解码为utf-8
read_info = response.read()
# decode() 默认utf-8
# 打印网页html的信息
# print(read_info.decode())

# 输出状态码
print(response.getcode())
# 输出链接地址
print(response.geturl())
"""
response.read()  读取文件的全部内容，返回的是byte类型
response.getcode()  获取HTTP的响应码
response.geturl()  获取实际url链接地址 防止重定向问题
response.info()  获取服务器响应的HTTP报头
"""
